package com.example.system.controller.question;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.Result;
import com.example.common.core.domain.TableDataInfo;
import com.example.common.core.enums.ResultCode;
import com.example.system.domain.question.dto.QuestionAddDTO;
import com.example.system.domain.question.dto.QuestionEditDTO;
import com.example.system.domain.question.dto.QuestionQueryDTO;
import com.example.system.service.question.QuestionService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author 23050
 * @version 1.0
 * @description: 题目管理类
 * @date 2025/2/16 19:54
 */
@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController {



    @Resource
    private QuestionService questionService;

    /**
     * @author 23050
     * @description:  列表请求方法
     * @date: 2025/2/16 20:07
     * @param questionQueryDTO  参数
     * @return com.example.common.core.domain.Result
     * 接口地址：/system/question/list
     */
    @GetMapping("/list")
    public TableDataInfo list(@RequestBody QuestionQueryDTO questionQueryDTO){
        return getTableDataInfo(questionService.list(questionQueryDTO));
    }



    /**
     * @author 23050
     * @description:
     * @date: 2025/2/20 19:46
     * @param questionAddDTO
     * @return com.example.common.core.domain.Result
     * /system/question/add
     */
    @PostMapping("/add")
    public Result add(@RequestBody QuestionAddDTO questionAddDTO){
        int ret = questionService.add(questionAddDTO);
        if (ret>0){
            return new Result(ResultCode.SUCCESS.getCode(),"添加成功","");
        }
        return new Result(ResultCode.FAILED.getCode(),"添加失败，请稍后重试","");
    }



    /**
     * @author 23050
     * @description:  查询题目详情
     * @date: 2025/2/20 20:43
     * @return com.example.common.core.domain.Result
     * /system/question/detail
     */
    @GetMapping("/detail")
    public Result detail(Long questionId){
        return new Result<>(ResultCode.SUCCESS.getCode(),"题目详情如下",questionService.detail(questionId));
    }

    /**
     * @author 23050
     * @description:  编辑题目
     * @date: 2025/2/20 21:31
     * @param questionEditDTO
     * @return com.example.common.core.domain.Result
     * /system/question/edit
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody QuestionEditDTO questionEditDTO){

        int ret = questionService.edit(questionEditDTO);
        if (ret>0){
            return new Result(ResultCode.SUCCESS.getCode(),"更新成功","");
        }
        return new Result(ResultCode.FAILED,"更新失败","");

    }


    /**
     * @author 23050
     * @description:  删除题目
     * @date: 2025/2/20 21:32
     * @param questionId
     * @return com.example.common.core.domain.Result
     * /system/question/delete
     */
    @DeleteMapping("/delete")
    public Result delete(Long questionId){
        int ret = questionService.delete(questionId);
        if (ret>0){
            return new Result(ResultCode.SUCCESS.getCode(),"删除成功","");
        }
        return new Result(ResultCode.FAILED.getCode(),"删除失败","");
    }




}
